//
//  PurchaseGoodLikeCell.m
//  danpin
//
//  Created by chuangjia on 26/8/15.
//  Copyright (c) 2015 chuangjia. All rights reserved.
//

#import "GoodLikeCell.h"

@interface GoodLikeCell()
@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UIScrollView *imageScroll;
@end
@implementation GoodLikeCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.backgroundColor=[UIColor clearColor];
        
        _imageScroll=[[UIScrollView alloc]initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH, 0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2, 30)];
        _imageScroll.pagingEnabled = YES;
        _imageScroll.showsHorizontalScrollIndicator = NO;
        _imageScroll.showsVerticalScrollIndicator = NO;
        _imageScroll.scrollsToTop = NO;
        [self.contentView addSubview:_imageScroll];
    }
    return self;
}
-(void)dealloc
{
    self.data=nil;
    self.key=nil;
    self.imageScroll=nil;
    //    DLog(@"%s", __PRETTY_FUNCTION__);
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
}
/// 根据数据模型来显示内容
- (void)showInfo:(id)model indexPath:(NSIndexPath *)indexPath
{
    NSArray *tagAr =(NSArray *)model;
    self.data =model;
    self.indexPath =indexPath;
    _imageScroll.frame =CGRectMake(PHOTO_FRAME_WIDTH,0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2, PHOTO_FRAME_WIDTH*5);
    _imageScroll.contentSize = CGSizeMake(PHOTO_FRAME_WIDTH*4 * [tagAr count], _imageScroll.frame.size.height);
    for (int i=0;i<[tagAr count];i++) {
        NSDictionary *dict =[tagAr objectAtIndex:i];
        UIImageView *iconView =[[UIImageView alloc] init];
        iconView.frame=CGRectMake(i*PHOTO_FRAME_WIDTH*4, PHOTO_FRAME_WIDTH, PHOTO_FRAME_WIDTH*3, PHOTO_FRAME_WIDTH*3);
        iconView.tag =i;
        iconView.layer.cornerRadius=PHOTO_FRAME_WIDTH*1.5;
        iconView.layer.masksToBounds = YES;
        [iconView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", [dict objectForKey:@"largeFace"]]] placeholderImage:[UIImage imageNamed:@"user_face.png"]];
        UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
        btn.backgroundColor=[UIColor clearColor];
        btn.frame =iconView.frame;
        btn.tag = i;
        [btn addTarget:self action:@selector(clickEvent:) forControlEvents:UIControlEventTouchUpInside];
        [_imageScroll addSubview:btn];
        [_imageScroll addSubview:iconView];
        iconView=nil;
    }
    [self layoutSubviews];
}

/// 返回Cell高度
+ (CGFloat)returnCellHeight:(id)model
{
    return PHOTO_FRAME_WIDTH*5;
}
-(void)setCallBack:(void(^)(BEventType,UIView*,id,id,NSIndexPath *))callback
{
    self.actionBlock=callback;
}

-(void)clickEvent:(id)sender
{
    UIButton *gest =(UIButton*)sender;
    id dict =[self.data objectAtIndex:gest.tag];
    if (dict && [dict isKindOfClass:[NSDictionary class]]) {
        if (self.actionBlock) {
            self.actionBlock(BEventType_sunUser,self,dict,nil,self.indexPath);
        }
    }
}

@end
